﻿using Dyao.Book.Contract.Serialization;

namespace Dyao.Book.Contract
{
    /// <summary>
    /// 任务记录页面
    /// </summary>
    public class TaskCenterRecordPageDto
    {
        /// <summary>
        /// 主键
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 分类
        /// </summary>
        [StringEnum]
        public TaskCenterCategoryEnum Category { get; set; }

        /// <summary>
        /// 任务配置Id
        /// </summary>
        public string TaskCenterSettingsId { get; set; }

        /// <summary>
        /// 任务配置名称
        /// </summary>
        public string TaskCenterSettingsName { get; set; }

        /// <summary>
        /// 菜单路径
        /// </summary>
        public string MenuPath { get; set; }

        /// <summary>
        /// 运行开始时间
        /// </summary>
        public DateTime? ExcuteBeginDatetime { get; set; }

        /// <summary>
        /// 运行结束时间
        /// </summary>
        public DateTime? ExcuteEndDatetime { get; set; }

        /// <summary>
        /// 执行时长
        /// </summary>
        public string ExcuteTimeText
        {
            get
            {
                if (ExcuteEndDatetime.HasValue && ExcuteBeginDatetime.HasValue)
                {
                    TimeSpan timeSpan = ExcuteEndDatetime.Value - ExcuteBeginDatetime.Value;
                    var totalSeconds = (int)timeSpan.TotalSeconds;
                    if (totalSeconds < 60)
                    {
                        return totalSeconds + "秒";
                    }
                    else if (totalSeconds >= 60 && totalSeconds < 60 * 60)
                    {
                        return $"{totalSeconds / 60}分{totalSeconds % 60}秒";
                    }

                    return $"{totalSeconds / 60 / 60}小时{(totalSeconds / 60) % 60}分{totalSeconds % 60}秒";
                }
                return "";
            }
        }

        /// <summary>
        /// 状态
        /// </summary>
        [StringEnum]
        public TaskCenterRecordStatusEnum Status { get; set; }

        /// <summary>
        /// ResultMessage
        /// </summary>
        public string ResultMessage { get; set; }

        /// <summary>
        /// CreateDateTime
        /// </summary>
        public DateTime CreateDateTime { get; set; }
    }
}